<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\GroupOrderBatch;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class GroupOrderBatchController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new GroupOrderBatch(['product','user']), function (Grid $grid) {

            $grid->column('id')->sortable();
            $grid->disableCreateButton();
            $grid->disableRefreshButton();
            $grid->disableViewButton();
            $grid->disableRowSelector();
            $grid->disableActions();
//            $grid->column('group_date');
            $grid->column('end_date');
            $grid->column('user.name', '会员名');
            $grid->column('user.flag', '会员标签');
            $grid->column('user.telephone', '会员电话')->copyable();
            $grid->column('product.name', '商品名称');
            $grid->column('reward_amount');
//            $grid->column('product_id');
            $grid->column('type','奖励类型')->using([
                1 => '奖金',
                2 => '分红积分'
            ]);
//            $grid->column('batch');
            $grid->column('status')->using([
                0 => '拼团中',
                1 => '已结束'
            ]);
            $grid->column('for_sale')->using([
                0 => '待处理',
                1 => '挂售中',
                2 => '已结算',
                3 => '申请提货'
            ]);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->selector(function (Grid\Tools\Selector $selector) {
                $selector->select('for_sale', [
                    0 => '待处理',
                    1 => '挂售中',
                    2 => '已结算',
                    3 => '申请提货'
                ]);
                $selector->select('status', [
                    0 => '拼团中',
                    1 => '已结束'
                ]);

            });
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->like('user.telephone', '会员电话');
                $filter->equal('user.flag', '会员标签');
                $filter->equal('order.product.name', '商品名称');
                $filter->equal('type','奖励类型')->select([
                    1 => '奖金',
                    2 => '分红积分'
                ]);
                $filter->equal('status')->select([
                    0 => '拼团中',
                    1 => '已结束'
                ]);
                $filter->equal('for_sale')->select([
                    0 => '待处理',
                    1 => '挂售中',
                    2 => '已结算',
                    3 => '申请提货'
                ]);
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new GroupOrderBatch(), function (Show $show) {
            $show->field('id');
            $show->field('group_date');
            $show->field('end_date');
            $show->field('user_id');
            $show->field('reward_amount');
            $show->field('product_id');
            $show->field('type');
            $show->field('batch');
            $show->field('status');
            $show->field('for_sale');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new GroupOrderBatch(), function (Form $form) {
            $form->display('id');
            $form->text('group_date');
            $form->text('end_date');
            $form->text('user_id');
            $form->text('reward_amount');
            $form->text('product_id');
            $form->text('type');
            $form->text('batch');
            $form->text('status');
            $form->text('for_sale');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
